﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.Business;

namespace QuanLyThuVien.DataAccess
{
    class TacGiaDAL
    {
        clsDatabase db = new clsDatabase();
        public void ThemMoiTG(TacGia tg)
        {
            db.ThuThiSQL("insert into tbTG values(N'" + tg.MaTG + "',N'" + tg.TenTG + "',N'" + tg.DiaChi + "',N'" + tg.DienThoai + "',N'"+tg.Email+"')");
        }

        public void SuaTG(TacGia tg)
        {
            db.ThuThiSQL("update tbTG set TenTG=N'" + tg.TenTG + "',DiaChi=N'" + tg.DiaChi + "',SDT=N'" + tg.DienThoai + "',Email=N'"+tg.Email+"' where MaTG=N'" + tg.MaTG + "'");
        }

        public void XoaTG(string maTG)
        {
            db.ThuThiSQL("delete from tbTG where MaTG=N'" + maTG + "'");
        }
        public void LoadLenDG(DataGridView dg)
        {
            db.LoadLenDG(dg, "select * from tbTG");
        }

        public bool KiemTraDL(string maTG)
        {
            return db.KiemTra("select count(*) from tbTG where MaTG=N'" + maTG + "'");
        }

        public void LoadLenCBTacGia(ComboBox cbTG)
        {
            db.LoadLenCombobox(cbTG, "select TenTG from tbTG", 0);
        }

        public string LoadLenMaTG(string MaTG, string TenTG)
        {
            MaTG = db.LoadLenLable("select MaTG from tbTG where TenTG=N'" + TenTG + "'");
            return MaTG;
        }

    }
}
